<template>
    <div>
      <h1>邮箱管理</h1>
       <el-row>
        <el-button type="primary" round  @click="drawer = true">发送</el-button>
      </el-row>
  
      <el-drawer
        title="发送邮件"
        :visible.sync="drawer"
        :direction="direction"
        :before-close="handleClose">
        <el-input v-model="email_receipt" placeholder="发件人"></el-input>
        <el-input v-model="email_data" placeholder="请输入邮箱内容"></el-input>
        <el-input v-model="title" placeholder="请输入标题"></el-input>
        <el-input v-model="url" placeholder="请输入地址"></el-input>
        <el-row>
          <el-button type="primary" round class="button" @click="add">确认发送</el-button>
        </el-row>
  
      </el-drawer>
  
      <el-table :data="user_list">
          <el-table-column label="所属员工邮箱" prop="employee"> </el-table-column>
          <el-table-column label="收件人邮箱" prop="email_receipt"> </el-table-column>
          <el-table-column label="邮箱内容" prop="email_data"> </el-table-column>
          <el-table-column label="标题" prop="title"> </el-table-column>
          <el-table-column label="地址" prop="url"> </el-table-column>
        <el-table-column label="操作" width="200px">
            <template slot-scope="scope">
            <el-button size="mini" @click="update(scope.row.id)">编辑</el-button>
            <el-button size="mini" type="danger" @click="del(scope.row.id)">删除</el-button>
            </template>
        </el-table-column>
        </el-table>
  
      <el-dialog
    title="修改邮箱"
    :visible.sync="dialogVisible"
    :before-close="handleClose">
    <el-input v-model="list2.email_receipt" placeholder="请输入收件人邮箱"></el-input>
    <el-input v-model="list2.email_data" placeholder="请输入邮箱内容"></el-input>
    <el-input v-model="list2.title" placeholder="请输入标题"></el-input>
    <el-input v-model="list2.url" placeholder="请输入地址"></el-input>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="xiugai">确 定</el-button>
    </span>
  </el-dialog>
    </div>
  </template>
  
  <script>
  export default {
       data(){
      return{
        user_list:[],
        drawer:false,
        dialogVisible:false,
        direction: 'rtl',
  
        direction: 'rtl',
        email_receipt:"",
        email_data:"",
        title:"",
        url:"",
  
        list2:{
          id:"",
          email_receipt:"",
          email_data:"",
          title:"",
          url:""
        }
  
      }
    },
    methods:{
      xiugai(){
        this.$axios.put("works/api/v1/addemail/" + this.list2.id +  "/",{
          email_receipt:this.list2.email_receipt,
          email_data:this.list2.email_data,
          title:this.list2.title,
          url:this.list2.url
          },{
             headers:{
            token:localStorage.getItem("token")
          }
          })
        .then(ree=>{
          if (ree.data.cdoe == 200){
            alert(ree.data.msg)
            this.getData()
          }else{
            alert(ree.data.msg)
          }
        }).catch(ss=>{
          console.log(ss)
        })
  
      },
      update(id){
        this.dialogVisible = true
        this.$axios.get("works/api/v1/addemail/" + id +  "/",{
          headers:{
            "token":localStorage.getItem("token")}
          }
        )
        .then(ree=>{
          this.list2 = ree.data.data
        }).catch(ss=>{
          console.log(ss)
        })
      },
            handleClose(done) {
          this.$confirm('确认关闭？')
            .then(_ => {
              done();
            })
            .catch(_ => {});
        },
  
  
      add(){
        this.$axios.post("works/api/v1/addemail/",{
          email_receipt:this.email_receipt,
          email_data:this.email_data,
          title:this.title,
          url:this.url
        },{
          headers:{
            "token":localStorage.getItem("token")
          }
        }).then(ree=>{
          if (ree.data.code == 200){
            alert(ree.data.msg)
            this.getData()
          }else{
            alert(ree.data.msg)
          }
        }).catch(ss=>{
          console.log(ss)
        })
      },
      del(id){
        this.$axios.delete("works/api/v1/addemail/" + id + "/",{
          headers:{
            "token":localStorage.getItem("token")
          }
        })
        .then(ree=>{
          if (ree.data.code == 200){
            alert(ree.data.msg)
            this.getData()
          }else{
            alert(ree.data.msg)
          }
        }).catch(ss=>{
          console.log(ss)
        })
      },
      getData(){
          this.$axios.get("works/api/v1/addemail/",{
            headers:{
                  token:localStorage.getItem("token")
              }
          })
      .then(ree=>{
        this.user_list = ree.data.data
      }).catch(ss=>{
        console.log(ss)
      })
      }
        
    },
    mounted(){
      this.getData()
      
    },
  
  }
  </script>
  
  <style>
  
  </style>